package com.wu.server.dao;

import com.wu.server.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

public interface UserRepository extends CrudRepository<User, Integer> {
    @Query(value = "select * from jd_shop.user where user_name = ?1",nativeQuery = true)
    User getUserInfoByUserName(String user_name);
    @Query(value = "select * from jd_shop.user where (id = ?1 or ?1 is null ) and" +
            "(nick_name like ?2 or ?2 is null)"
            ,nativeQuery = true)
    Page<User> queryUserBy(String idQuery, String nickNameQuery, Pageable pageable);

    @Transactional
    @Modifying
    @Query(value = "delete from jd_shop.user where id = ?1", nativeQuery = true)
    void deleteUserById(String id);
}
